#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m, k;
int hor, ver;
vector<int> hs, vs;
int he, ho, ve, vo;
void reset() {
    hor=ver=0;
    hs.clear(); vs.clear();
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef local
    freopen("in.txt", "r", stdin);
    #endif // local
    int tc; cin>>tc;
    while(tc--) {
        reset();
        cin>>n>>m>>k;
        int res = n*m%2;
        for(int i=0; i<k; ++i) {
            int a, b; cin>>a>>b;
            if(a==0) {
                hor++;hs.push_back(b);
                if(b%2==1) {
                    ho++;
                }
                else {
                    he++;
                }
            }
            else {
                ver++;vs.push_back(b);
                if(b%2==1) {
                    vo++;
                }
                else {
                    ve++;
                }
            }
        }
        if(n%2==1) {
            res = res - vo + ve;
        }
        if(m%2==1) {
            res = res - ho + ve;
        }
        res += (ve*he + vo*ho -vo*he - ve*ho);
        /*if(n%2==1) {
            for(int el:vs) {
                if(el%2==1) res--;
                else res++;
            }
        }
        if(m%2==1) {
            for(int el:hs) {
                if(el%2) res--;
                else res++;
            }
        }*/
        /*for(int a:hs) {
            for(int b:vs) {
                if(a%2==b%2) res++;
                else res--;
            }
        }*/
        cout<<res<<'\n';
    }
}
